##
## Makefile for plazza in ...
##
## Made by kevin duchassin
## Login   <duchas_k@epitech.net>
##
## Started on  Wed Apr 10 14:51:48 2013 kevin duchassin
## Last update Sun Apr 21 16:09:24 2013 kevin duchassin
##

CXX		= g++
MOC		= moc#-qt4

NAME 		= plazza

SRCS_DIR	= sources
#INCS_DIR	= includes
INCS_DIR	= $(SRCS_DIR)
INCS_DIR	+= -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui
INCS_DIR	+= -I/usr/include/qt4 -I/usr/include/Qt -I/usr/include/QtGui
INCS_DIR	+= -I/usr/include/QtCore

QT_SRCS		= $(SRCS_DIR)/GUI/MainWindow.cpp

SRCS 		= $(QT_SRCS:.cpp=.moc.cpp) \
		$(QT_SRCS) \
		$(wildcard $(SRCS_DIR)/Options/*.cpp) \
		$(wildcard $(SRCS_DIR)/Pizzeria/*.cpp) \
		$(wildcard $(SRCS_DIR)/Pizzeria/Communication/*.cpp) \
		$(wildcard $(SRCS_DIR)/Utils/*.cpp) \
		$(wildcard $(SRCS_DIR)/Wrappers/Pthread/*.cpp) \
		$(wildcard $(SRCS_DIR)/Wrappers/UnixUtils/*.cpp)

ifeq		($(TESTS), yes)
TEST_WARNING	= @echo "/!\ Program linked with main_test.c since TESTS = yes"
SRCS		+= $(SRCS_DIR)/main_tests.cpp \
		$(wildcard $(SRCS_DIR)/UnitTest/*.cpp) \
		$(wildcard $(SRCS_DIR)/Wrappers/Pthread/Tests/*.cpp) \
		$(wildcard $(SRCS_DIR)/Wrappers/UnixUtils/Tests/*.cpp) \
		$(wildcard $(SRCS_DIR)/Pizzeria/Tests/*.cpp)
else
TEST_WARNING	=
SRCS		+= $(SRCS_DIR)/main.cpp
endif

OBJS		= $(SRCS:.cpp=.o)

CXXFLAGS	= -W -Wall -Wextra -I $(INCS_DIR) -pipe -pthread
CXXFLAGS	+= -lQtGui -lQtCore

ifeq		($(DEBUG), yes)
CXXFLAGS	+= -g3 -ggdb
else ifeq	($(PROF), yes)
CXXFLAGS	+= -O2 -pg
else
CXXFLAGS	+= -O2
endif

$(NAME):	$(OBJS)
		$(CXX) -o $(NAME) $(OBJS) $(CXXFLAGS) $(LDFLAGS)
		$(TEST_WARNING)

all:		$(NAME)

-include	$(OBJS:.o=.dep)

clean:
		@rm -f $(OBJS)
		@rm -f $(OBJS:.o=.dep)

fclean: 	clean
		@rm -f doxygen.html
		@rm -fr doxygen
		@rm -f $(NAME)

re:		fclean all

doxygen:
		doxygen DoxyFile
		@rm -f doxygen.html
		@ln -s doxygen/html/index.html doxygen.html
		@echo "Doxygen generation done (./doxygen.html)"

.PHONY:		clean fclean re all doxygen

%.moc.cpp: %.hpp
		$(MOC) $< -o $@

%.o:	%.cpp
		$(CXX) -c $(CXXFLAGS) $*.cpp -o $*.o
		@$(CXX) -M $(CXXFLAGS) $*.cpp > $*.dep
		@mv -f $*.dep $*.dep.tmp
		@sed -e 's|.*:|$*.o:|' < $*.dep.tmp > $*.dep
		@sed -e 's/.*://' -e 's/\\$$//' < $*.dep.tmp | fmt -1 | \
		sed -e 's/^ *//' -e 's/$$/:/' >> $*.dep
		@rm -f $*.dep.tmp
